<?php

namespace app\commands;

use app\models\Brand;
use app\models\Images;
use app\models\product\ProductCategory;
use yii\console\Controller;
use yii\console\ExitCode;
use Yii;

/**
 * Class DeleteController
 * @package app\commands
 */
class ClearController extends Controller
{
    /**
     * php yii clear/all
     * =================================================
     * php yii clear/images
     * php yii clear/brand
     * php yii clear/category
     */

    public function actionAll()
    {
        $this->actionImages();
        $this->actionBrand();
        $this->actionCategory();
    }

    /**
     * Clear images
     *
     * @return int
     */
    public function actionImages()
    {
        Images::getDb()->createCommand()->truncateTable('images')->execute();
        // Images::deleteAll();
        echo 'Clear images ................. done!', "\n";
        return ExitCode::OK;
    }

    /**
     * delete brand list
     *
     * @return int
     */
    public function actionBrand()
    {
        // Brand::deleteAll();
        Brand::getDb()->createCommand()->truncateTable('brand')->execute();

        echo 'Clear brand ................. done!', "\n";
        return ExitCode::OK;
    }

    /**
     * delete category list
     *
     * @return int
     * @throws \yii\db\Exception
     */
    public function actionCategory()
    {
        ProductCategory::getDb()->createCommand()->truncateTable('product_category')->execute();

        echo 'Clear category ................. done!', "\n";
        return ExitCode::OK;
    }
}